/*	Copyright 2013 RangerUFO
 *
 *	This file is part of Libevent-helper.
 *
 *	Libevent-helper is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU Lesser General Public License as published by
 *	the Free Software Foundation, either version 3 of the License, or
 *	(at your option) any later version.
 *
 *	Libevent-helper is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU Lesser General Public License for more details.
 *
 *	You should have received a copy of the GNU Lesser General Public License
 *	along with Libevent-helper.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __libevent_helper_h__
#define __libevent_helper_h__

#ifdef __cplusplus
extern "C" {
#endif  // __cplusplus

#include <stddef.h>

typedef void* (*evhelper_malloc_fn)(size_t);
typedef void* (*evhelper_realloc_fn)(void*, size_t);
typedef void (*evhelper_free_fn)(void*);

int evhelper_init();

void evhelper_set_mem_functions(
		evhelper_malloc_fn malloc_fn,
		evhelper_realloc_fn realloc_fn,
		evhelper_free_fn free_fn);

void* evhelper_malloc(size_t n);
void* evhelper_realloc(void* p, size_t n);
void evhelper_free(void* p);


struct evtable;
struct evtable_node;

typedef void (*evtable_node_destroy_fn)(struct evtable_node*);

struct evtable* evtable_new(size_t n, evtable_node_destroy_fn destroy_fn);
void evtable_free(struct evtable* tb);

struct evtable_node* evtable_insert(struct evtable* tb, void* obj);
void evtable_remove(struct evtable* tb, struct evtable_node* tn);

void* evtable_node_deref(struct evtable_node* tn);
struct evtable* evtable_node_table(struct evtable_node* tn);

struct evtable_node* evtable_find(struct evtable* tb, void* obj);
struct evtable_node* evtable_get_first(struct evtable* tb);
struct evtable_node* evtable_get_next(struct evtable* tb, struct evtable_node* tn);

#ifdef __cplusplus
}
#endif  // __cplusplus

#endif  // __libevent_helper_h__
